package com.ist.service;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import com.ist.dao.VehicleDao;
import com.ist.data.Vehicle;

public class VehicleResource {

	@Context
	UriInfo uriInfo;
	@Context
	Request request;
	int id;
	
	public VehicleResource(UriInfo uriInfo, Request request, int id) {
		super();
		this.uriInfo = uriInfo;
		this.request = request;
		this.id = id;
	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public Vehicle getVehicle() {
		return VehicleDao.getInstance().findVehicle(id);
	}
	
	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	public Integer updateVehicle(Vehicle vehicle) {
		return VehicleDao.getInstance().saveOrUpdateVehicle(vehicle);
	}
	
	@DELETE
	public void deleteVehicle() {
		VehicleDao.getInstance().deleteVehicle(VehicleDao.getInstance().findVehicle(id));
	}
	
}
